using Microsoft.SqlServer.Management.Sdk.Sfc;
using System;
using System.IO;
using System.Text;

namespace Microsoft.SqlServer.Management.SqlManagerUI.Scripting
{
	internal class SingleFileWriterProvider : TextWriterProvider
	{
		private string fileName;

		private ScriptToFileMode fileMode;

		private Encoding encoding;

		public SingleFileWriterProvider(string fileName, ScriptToFileMode fileMode, Encoding encoding)
		{
			if (fileName == null)
			{
				throw new ArgumentNullException("fileName");
			}
			string directoryName = Path.GetDirectoryName(fileName);
			if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName))
			{
				throw new DirectoryNotFoundException(directoryName);
			}
			this.fileName = fileName;
			this.fileMode = fileMode;
			this.encoding = encoding;
		}

		public override TextWriter GetTextWriter(Urn item)
		{
			return new StreamWriter(this.fileName, this.fileMode == ScriptToFileMode.Append, this.encoding);
		}
	}
}
